home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with a for loop
- Date: 5 Mar 1996 00:09:23 GMT
- Organization: Borland International
- Message-ID: <4hg0nj$amq@druid.borland.com>
- References: <4h8g0l$1ot@nic.umass.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4h8g0l$1ot@nic.umass.edu>, ksexton@wilde.oit.umass.edu says...
- >
- >Hi.
- >I was doing a project for one of my classes and I came across a rather
- >odd bug in part of the code. I initially had the following:
- >for ( i = 0; WL[i] != NULL, i <= 10; i++ )
- >{
- > AAL[i] = new char[strlen(WL[i])+1);
- > strcpy(AAL[i], WL[i]);
- >}
- >
- >I realize that new belongs to C++, but that's not where the confusion
- >lies. WL is an array of pointers to strings. WL[0]="./my_macro" and
- >WL[1]=NULL. However, the for loop insists on continuing the loop even
- >when i=1 and WL[i]=NULL. Am I missing something? I can't see what is
- >wrong logically. Any assistance would be much appreciated. Thanx in
- >advance.
-
- Look carefully at the test condition in the for loop:
-
- WL[i] != NULL, i <= 10;
-
- then think about what the comma operator does.
- -- Pete
-
-